#include "button.h"


Button::Button(const char* file,GLfloat width,GLfloat height):m_position{0,0}
{
    m_position.x = 0;
    m_position.y = 0;
    m_wrap = 0;
    m_wrap = new SinglePictureRenderWrap(file,width,height);
}
Button::~Button()
{
    delete m_wrap;
    m_wrap = 0;
}

bool Button::isClickArea(int x,int y)
{
    Size picSize = m_wrap->getSinglePicture()->getSize();

    if( x < m_position.x || x > m_position.x + picSize.width )
    {
        return false;
    }

    if( y < m_position.y || y > m_position.y + picSize.height )
    {
        return false;
    }

    return true;
}

void Button::clicked(int x,int y)
{
    try
    {
        m_function(x,y);
    }
    catch(const std::bad_function_call& e)
    {
        throw e;
    }
}

void Button::render()
{
    m_wrap->render(m_position.x,m_position.y);
}

void Button::update()
{
    m_wrap->update();
}
